package OutputStream;

import POJO.Dog;
import org.junit.jupiter.api.Test;

import java.io.*;

public class ObjectOutputStreamTest {

    @Test
    public void test() throws IOException {

        //将对象序列化后，保存的文件是dat格式
        String filePath = "D:\\aaaa\\data.dat";
        FileOutputStream fileOutputStream = new FileOutputStream(filePath);

        ObjectOutputStream outputStream = new ObjectOutputStream(fileOutputStream);

        outputStream.writeInt(100);//保存Integer 100
        outputStream.writeBoolean(true);//保存Boolean true
        outputStream.writeChar('a');//保存 Char 'a'
        outputStream.writeDouble(9.5);//保存 Double 9.5
        outputStream.writeUTF("张瑞阳");//保存String "张瑞阳"
        outputStream.writeObject(new Dog("豆豆"));//保存dog对象

        //关闭流
        outputStream.close();


    }
}
